package com.group9.handinhand.dao.model;

import java.util.Arrays;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.ServicesSO;

@Entity
@Table(name = "SERVICES")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Services extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "SKILL_ID", nullable = false)
	private Skill requiredSkill;
	
	@Column(name = "REQUIRED_NUMBER", nullable = false)
	private int requiredNumber;
	
	@Column(name = "RESPONDED_AMOUNT", nullable = false)
	private int respondedAmount;

	public ServicesSO convertToServiceObject(String... ignoreProperties) {
		ServicesSO so = convert(new ServicesSO(), (String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"requiredSkill"}));
		if( ! Arrays.asList(ignoreProperties).contains("reqiredSkill"))
			if(requiredSkill != null) {
				so.setRequiredSkill(requiredSkill.convertToServiceObject());
			}
		return so;
	}

	public Skill getRequiredSkill() {
		return requiredSkill;
	}

	public void setRequiredSkill(Skill requiredSkill) {
		this.requiredSkill = requiredSkill;
	}

	public int getRequiredNumber() {
		return requiredNumber;
	}

	public void setRequiredNumber(int requiedNumber) {
		this.requiredNumber = requiedNumber;
	}

	public int getRespondedAmount() {
		return respondedAmount;
	}

	public void setRespondedAmount(int respondedAmount) {
		this.respondedAmount = respondedAmount;
	}

	@Override
	public String toString() {
		return "Services [requiredSkill=" + requiredSkill + ", requiredNumber="
				+ requiredNumber + ", respondedAmount=" + respondedAmount + "]";
	}


}
